<?php

class PhpWind
{
    static function setCookie($name, $value, $time){
        global $db_cookiepre, $db_cookiepre, $db_sitehash;
        $per = ($db_cookiepre) ? $db_cookiepre : substr(md5($db_sitehash), 0, 5);
        return setcookie($per.'_'.$name, $value, $time, '/', '.sudingke.com');
    }

    static function getCookie($name){
        global $db_cookiepre, $db_cookiepre, $db_sitehash;
        $per = ($db_cookiepre) ? $db_cookiepre : substr(md5($db_sitehash), 0, 5);
        return $_COOKIE[$per.'_'.$name];
    }

    /**
     * 加密、解密字符串
     *
     * @global string $db_hash
     * @global array $pwServer
     * @param $string 待处理字符串
     * @param $action 操作，ENCODE|DECODE
     * @return string
     */
    static function strCode($string, $action = 'ENCODE') {
        global $db_hash;
        $action != 'ENCODE' && $string = base64_decode($string);
        $code = '';
        $key = substr(md5($_SERVER['HTTP_USER_AGENT'] . $db_hash), 8, 18);
        $keyLen = strlen($key);
        $strLen = strlen($string);
        for ($i = 0; $i < $strLen; $i++) {
            $k = $i % $keyLen;
            $code .= $string[$i] ^ $key[$k];
        }
        return ($action != 'DECODE' ? base64_encode($code) : $code);
    }

    static function checkLogin($user, $pwd, $time = 0, $safe = '') {
        if(empty($user)){
            $error = '用户名为空';
        }
        if(empty($pwd)){
            $error = '密码为空';
        }
    }

    /**
     * 获取客户端唯一hash
     *
     * @param string $str 附加信息
     * @param string $app
     * @return string
     */
    function GetVerify($str, $app = null) {
        global $db_siteid;
        empty($app) && $app = $db_siteid;
        return substr(md5($str . $app . $_SERVER['HTTP_USER_AGENT']), 8, 8);
    }
}
?>